<?php
/**
 * Created by PhpStorm.
 * User: FEIFEI
* Date: 2018/6/25
* Time: 19:19
*/




/**
 **发布编辑合同
 **/
 function contractAdd()
{
    $contractInfo=array();//储存用户输入的内容

    $id=$_GET['id'];
    $action=$_GET['action'];

    if($id>0){ //编辑  获取页面数据
        $data =array(
            'contractId' => $id,
        );  //定义参数
        $url = INTERFACE_ADDRESS.'/api/contract/contractTemplateById';
        $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
        $response = $this->tocurlPost($url, $header,$data);
        $info = json_decode($response, true);
        print_r($info);

        $this->assign('data',$info['data']);
    }



    if ($action == 'step1') {//合同发布第一步
        //获取印章列表
        $page = $_REQUEST['pages'] ? (int)$_REQUEST['pages'] : 1;
        $url = INTERFACE_ADDRESS . '/api/seal/sealListBy?pageSize=10&pages=' . $page;
        $header = array('bAccessToken:' . $_SESSION['bAccessToken'], 'language:zh', 'region:GZ');
        $response = $this->tocurlGet($url, $header);
        $file_contents = json_decode($response, true);

        $sealList = $file_contents['data']['records'];

        $this->assign('sealList', $sealList);
        print_r($sealList);


        if ($_SERVER["REQUEST_METHOD"] === "POST"){//点击下一步

            //获取用户输入的数据
            $name=$_POST['name'];
            $select=$_POST['seal'];
            $content=strip_tags($_POST['content']);
            if(empty($name)){
                echo "<script>alert('标题不能为空,请重新输入！')</script>";
//                    return false;
            }
            if(empty($content)){
                echo "<script>alert('内容不能为空,请重新输入！')</script>";
//                    return false;
            }


            $contractInfo['name']=$name;
            $contractInfo['select']=$select;
            $contractInfo['content']=$content;

//                        print_r($contractInfo);

            session('contractInfo',$contractInfo);//保存第一步用户输入的数据
            header('Location:http://'. $_SERVER['HTTP_HOST'].'/Admin/Admin/contractAdd/action/step2.html');
        }

        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('contract_add');

    }//step1 end


    if ($action == 'step2') {//合同发布第二步
//                print_r($_SESSION['contractInfo']);
        if ($_SERVER["REQUEST_METHOD"] === "POST"){ //点击提交
//                    print_r($_REQUEST);exit;
            //印章数据处理
            $sealData = doSealData($_REQUEST['sealCoordinate'],$_REQUEST['sealCoordinateLen']);
            $signData = doSealData($_REQUEST['signCoordinate'],$_REQUEST['signCoordinateLen']);
            $signatoryData = doSealData($_REQUEST['signatoryCoordinate'],$_REQUEST['signatoryCoordinateLen']);

            $jsonSealData=json_encode($sealData);
            $jsonSignData=json_encode($signData);
            $jsonSignatoryData=json_encode($signatoryData);
//print_r($jsonSealData);exit;


            $data =array(
                'name' => $_SESSION['contractInfo']['name'],
                'sealId' => $_SESSION['contractInfo']['select'],
                'content' => $_SESSION['contractInfo']['content'],
                'signatoryPst' => $jsonSignatoryData,
                'sealPst' => $jsonSealData,
                'signedPst' => $jsonSignData,

            );  //定义参数
            $url = INTERFACE_ADDRESS.'/api/contract/addContractTemplate';
            $header = array('bAccessToken:'.$_SESSION['bAccessToken'],'language:zh','region:GZ');
            $response = $this->tocurlPost($url, $header,$data);
            $info = json_decode($response, true);

            print_r($info);exit;


//                    print_r($_SESSION['contractInfo']);exit;
        }

        $this->assign('contractInfo',$_SESSION['contractInfo']);

        $this->assign('loginName',$_SESSION['loginName']);
        $this->display('contractAddStep2');
    }//step2 end





}




